<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.util.CodeTableUtil"%>
<%@page import="com.feib.soeasy.model.Payment"%>
<%@page import="com.feib.soeasy.model.UploadFile"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.feib.soeasy.action.Soez3001ActionBean"%>
<%
Soez3001ActionBean actionBean = (Soez3001ActionBean) request.getAttribute("actionBean");
SimpleDateFormat sd = new SimpleDateFormat("yyyyMMdd");
String today = sd.format(Calendar.getInstance().getTime());
%>

<script type="text/javascript">
	<!--	
	$(document).ready(function() {	
		$("[id^='viewPaymentImg-']").click(function() {
			var paymentPk = this.id.substring(15);
			doQueryPaymentsAction(paymentPk);
			
		});
		
		$('#printBtn2').click(function() {
			divPrint('queryResultDiv');//只印目前這筆
		});
		
	});
	
	
	$("#checkAll").click(function() {
		doCheckAll();
	});
	
	$("#unCheckAll").click(function() {
		undoCheckAll();
	});
	
	function checkRadio()
	{
		var isDoComfirm = false;
		$('#downloadHiddenFrom input:checkbox.chk').each(function(){               
        	if ( $(this).attr('checked') ){
        		isDoComfirm = true;
        	}
       	});
		if(!isDoComfirm)
		{
			alert('請選擇下載帳單!!');
			return false;
		}
	}
	
	
	//-->
	</script>
	
<c:choose>
	<c:when test="${null != actionBean.queryResult && not empty actionBean.queryResult}">
		<stripes:form name="downloadHiddenFrom" id="downloadHiddenFrom" beanclass="com.feib.soeasy.action.Soez3001ActionBean" 
		method="post" >
			<table id="listTable">
				<thead>
					<tr>
						<tr>
						<th></th>
						<th>客戶編號</th>
						<th>姓名</th>
						<th>繳費期限</th>
						<th>繳費帳號</th>	
						<th>帳單名稱</th>											
						<th>繳費金額</th>						
						<th>繳費狀態</th>
						<th>繳費明細</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${actionBean.queryResult}" var="viewObj" varStatus="rowstat">
					<tr>
						<td align="center">
						<input name="checkPayment[${rowstat.index}].pdfFilePathOnServer" 
							type="checkbox" 
							id="checkPayment[${rowstat.index}].pdfFilePathOnServer" 
							value="<c:out value='${viewObj.pdfFilePathOnServer}'/>" class="chk"/>
						</td>
				
						<td><c:out value="${viewObj.payerId}"/></td>
						<td><c:out value="${viewObj.payerName}"/></td>
						<td align="center"><fmt:formatDate value="${viewObj.payDue}" pattern="yyyy/MM/dd" /></td>							
						<td><c:out value="${viewObj.virtualAccount}"/></td>	
						<td><c:out value="${viewObj.paymentName}"/></td>	
						<td align="right"><c:out value="${viewObj.totalAmount}"/></td>
				<%
				Payment viewObj = (Payment)pageContext.getAttribute("viewObj");
				Integer paymentStatus = viewObj.getPaymentStatus();
				
				String paymentStatusName = CodeTableUtil.getInstance().getCodeName(CodeTableUtil.CODE_KIND_PAYMENT_STATUS, viewObj.getPaymentStatus().toString());
								
				// 判斷是否逾期
				if (Payment.PAYMENT_STATUS_IN_PAYING.equals(viewObj.getPaymentStatus()))
				{
				    String payDueStr = sd.format(viewObj.getPayDue());
				    if (today.compareTo(payDueStr) > 0)
				        paymentStatusName = "逾期";
				}
				
				pageContext.setAttribute("paymentStatusName", paymentStatusName);
				%>
						
						
						<td><c:out value="${paymentStatusName}" /></td>
						<td>
							<div id="viewPaymentImg-<c:out value='${viewObj.paymentPk}'/>"><a href="javascript: void(0)" class="btnZoom">查詢</a></div>
						</td>				
					</tr>
					</c:forEach>
				</tbody>
			</table>			
<div id="paginationBar">
	<input type="button" 
						id="checkAll" name="checkAll" 
						value="全選">
					<input type="button" 
						id="unCheckAll" name="unCheckAll" 
						value="全不選">
					<stripes:submit 
						id="doDownloadAction" name="doDownloadAction" 
						value="下載繳費單" onclick="return checkRadio();" />
</div>		
		
	</stripes:form>	
		
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			
			
		});
		//-->
		</script>
			
	</c:when>
	<c:otherwise>
		<div id="queryNothingBlockDiv" style="display: none;">
			
			<c:if test="${actionBean.overCountMessage != null}">
				${actionBean.overCountMessage }
			</c:if>
			
			
		</div>	
		<table id="listTable">
				<thead>
					<tr>
						<tr>
						<th></th>
						<th>客戶編號</th>
						<th>姓名</th>
						<th>繳費期限</th>
						<th>繳費帳號</th>	
						<th>帳單名稱</th>											
						<th>繳費金額</th>						
						<th>繳費狀態</th>
						<th>繳費明細</th>
					</tr>
				</thead>
		</table>	
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			$( "#queryNothingBlockDiv" ).dialog( "destroy" );
			$( "#queryNothingBlockDiv" ).dialog({  title:'<%=UserUtil.getCurrentMenuItemName() %>查詢' ,width: 300, resizable: false, modal: true, buttons : {
				Ok : function() {
					$(this).dialog("close");
				}
			}  });
		});
		//-->
		</script>
	</c:otherwise>
</c:choose>
